/**
 * 
 */
package com.ez.supervise.service.impl;

import java.util.List;

import com.ez.supervise.dao.UserRoleDao;
import com.ez.supervise.model.sys.RolePermission;
import com.ez.supervise.model.sys.UserRole;
import com.ez.supervise.service.UserRoleService;

/**
 * @author searph.wang
 * @email searph.wang@gmail.com
 * @Created at 2009-7-22
 * 
 */
public class UserRoleServiceImpl implements UserRoleService {
    private UserRoleDao userRoleDao;

    // public int update(UserRole userRole) {
    // return sqlMapClientTemplate.update("sys.updateUserRole", userRole);
    // }

    public void setUserRoleDao(UserRoleDao userRoleDao) {
	this.userRoleDao = userRoleDao;
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#delete(java.lang.Long)
     */
    public void delete(Long id) {
	// TODO Auto-generated method stub
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#insert(java.lang.Object)
     */
    public void insert(Object entity) {
	userRoleDao.insert(entity);

    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#update(java.lang.Object)
     */
    public void update(Object entity) {
	userRoleDao.update(entity);
    }

    /*
     * (non-Javadoc)
     * 
     * @see com.ez.supervise.service.base.BaseService#get(java.lang.Long)
     */
    public Object get(Long id) {
	return (UserRole) userRoleDao.get(id);
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.ez.supervise.service.UserRoleService#saveRolePermissionByRoleId(java
     * .lang.Long, java.lang.Long[])
     */
    public void saveRolePermissionByRoleId(Long userId, Long[] ids) {
	userRoleDao.deleteUserRoleByUserid(userId);
	UserRole ur = null;
	for (Long roleId : ids) {
	    ur = new UserRole(userId, roleId);
	    userRoleDao.insert(ur);
	}
    }

    /*
     * (non-Javadoc)
     * 
     * @see
     * com.ez.supervise.service.UserRoleService#findUserRoleByUserId(java.lang
     * .Long)
     */
    public List findUserRoleByUserId(Long userId) {
	return userRoleDao.findUserRoleByUserId(userId);
    }
}
